{ Statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=1394
  Verdict: Accepted
}
uses
	SysUtils, Math;
 
type
	stack = object
		a : array of longint;
		procedure push(v : longint);
		procedure pop();
		function back() : longint;
		function size() : longint;
		procedure clear();
	end;
 
procedure stack.push(v : longint);
 
var
	tt : longint;
 
begin
	tt := length(a);
	setlength(a, tt + 1);
	a[tt] := v;
end;
 
procedure stack.pop();
 
var
	tt : longint;
 
begin
	tt := length(a);
	if tt = 0 then exit;
	setlength(a, tt - 1);
end;
 
function stack.back() : longint;
begin
	if length(a) = 0 then begin
		result := 0;
		exit;
	end;
	result := a[length(a) - 1];
end;
 
function stack.size() : longint;
begin
	result := length(a);
end;
 
procedure stack.clear();
begin
	setlength(a, 0);
end;
 
var
	i, n, t : longint;
	a, c, l, r : array[0..200010] of int64;
	s : stack;
	ans : int64;	
 
begin
	reset(input,'input.txt');
	rewrite(output,'output.txt');
	read(n, t);
	for i := 1 to n do 
		read(a[i]);
	fillchar(l, sizeof(l), 0);
	fillchar(r, sizeof(r), 0);
	fillchar(c, sizeof(c), 0);
	s.push(1);
	for i := 2 to n do begin
		while (a[s.back()] < a[i]) and (s.size() > 0) do begin
			inc(l[i], l[s.back()] + 1);
			s.pop();
		end;
		s.push(i);
	end;
	s.clear();
	s.push(n);
	for i := n - 1 downto 1 do begin
		while (a[s.back()] < a[i]) and (s.size() > 0) do begin
			inc(r[i], r[s.back()] + 1);
			s.pop();
		end;
		s.push(i);
	end;
	c[0] := 0;
	for i := 1 to n do
		c[i] := c[i - 1] + l[i] + r[i];
	ans := 0;
	for i := 1 to n do
		ans := max(ans, c[i + t - 1] - c[i - 1]);
	write(ans);
end.